import { App, defineAsyncComponent } from "vue";
import directives from "./directives";
import { useBaseTable } from "./hooks/useBaseTable";
import { useWriteTable } from "./hooks/useWriteTable";

//所有组件列表
const components = import.meta.glob("./components/*/src/*.vue");

// 所有指令
// const directives = [];
//过滤器
// const filters = [];

const install = (app: App) => {
  // 遍历组件模块实现自动注册
  for (const [key, value] of Object.entries(components)) {
    console.log();
    const componentName = key.split("/").pop()?.split(".")[0];

    if (componentName) {
      app.component(componentName, defineAsyncComponent(value as any));
    }

    //导入指令
    app.use(directives);
  }
};

export default { install, ...components };
export {
  //导出封装的hooks
  useBaseTable,
  useWriteTable,
};
